﻿using System;
using System.Data.Entity;
using Guan.CMS.Model.Entities;

namespace Guan.CMS.Data.Initialization
{
    public class CmsContextInitializer : DropCreateDatabaseIfModelChanges<CmsDataContext>
    {
        protected override void Seed(CmsDataContext context)
        {
            new ProductCategoryInit(context).Init();

            var supplierLenovo = new Supplier
                                     {
                                         CompanyName = "东莞市金商通信息科技有限公司",
                                         CompanyShortName = "金商通",
                                         CompanyAddress = "东莞市",
                                         CompanyTel = "0769-23133671 23133672 23133673",
                                         Linkman = "市场部直线",
                                         LinkmanPhone = "0769-23133673"
                                     };
            context.Suppliers.Add(supplierLenovo);
            for (var i = 1; i <= 50; i++)
            {
                var supplier = new Supplier
                {
                    CompanyName = "企业" + i,
                    CompanyShortName = "QiYe" + i,
                    CompanyAddress = "中国" + i,
                    CompanyTel = "010-58868888" + i,
                    Linkman = "张三" + i,
                    LinkmanPhone = "13111110003" + i
                };
                context.Suppliers.Add(supplier);
            }
            context.SaveChanges();
            for (int i = 0; i < 50; i++)
            {
                var product = new Product
                                  {
                                      Name = "产品" + i,
                                      IsPublished = true,
                                      CreatedTime = DateTime.Now,
                                      UpdatedTime = DateTime.Now
                                  };
                context.Products.Add(product);
            }
            context.SaveChanges();

           /* for (int i = 1; i <= 30; i++)
            {
                var file = new Media
                    {
                        CreatedTime = DateTime.Now,
                        ExtName = "jpg",
                        Name = "gallery_" + i,
                        Path = "~/Content/Images/gallery_1.jpg"
                    };
                var file2 = new Media
                {
                    CreatedTime = DateTime.Now,
                    ExtName = "txt",
                    Name = "gallery_" + i,
                    Path = "~/Content/Images/gallery_1.jpg"
                };
                context.Files.Add(file);
                context.Files.Add(file2);
            }
            context.SaveChanges();*/

            //文章分类
            var newsCategory = new ArticleCategory
                                   {
                                       Name = "公司新闻",
                                       Key = "news",
                                       IsPublished = true
                                   };
            context.ArticleCategories.Add(newsCategory);
            context.SaveChanges();

            //文章管理
            var art1 = new Article
                {
                    Title = "美称中国军舰锁定日舰加剧紧张 望和平对话",
                    Body =
                        "<p style=\"margin-bottom:0px;padding-right:0px;padding-bottom:29px;padding-left:0px;font-size:16px;line-height:28px;font-family:宋体, Arial, sans-serif;text-indent:2em;\"><img alt=\"\" src=\"/Uploadfiles/Images/13.jpeg\" style=\"display:block;margin-left:auto;margin-right:auto;\" /></p><p style=\"margin-bottom:0px;padding-right:0px;padding-bottom:29px;padding-left:0px;font-size:16px;line-height:28px;font-family:宋体, Arial, sans-serif;text-indent:2em;\">据日本媒体此前报道，日本防卫大臣小野寺五典5日晚召开紧急记者会，称日本军舰日前曾遭中国舰船火控雷达照射。日本新闻网2月6日报道，针对此事，美国国务院发言人纽兰在5日记者会上表示，这一行动会加剧钓鱼岛紧张局势，希望中日两国能通过和平对话解决钓鱼岛问题。</p><p style=\"margin-bottom:0px;padding-right:0px;padding-bottom:29px;padding-left:0px;font-size:16px;line-height:28px;font-family:宋体, Arial, sans-serif;text-indent:2em;\">报道称，纽兰代表美国国务院发表的声明称：“美国政府有关钓鱼岛的方针和关与姿态是不会改变的。”他强调钓鱼岛适用于日美安保范围的立场。纽兰还表示，偶发事件和误算等危险因素的增加，会给东亚地区的和平与稳定，给经济的发展带来损害。他希望中日两国就解决钓鱼岛岛问题展开和平对话。</p><p style=\"margin-bottom:0px;padding-right:0px;padding-bottom:29px;padding-left:0px;font-size:16px;line-height:28px;font-family:宋体, Arial, sans-serif;text-indent:2em;\">据日本媒体报道，日本防卫大臣小野寺五典5日晚召开紧急记者会，称1月30日10时日本“夕立”号护卫舰在东海公海海域遭中国护卫舰火控雷达“瞄准”，当时两舰相距3公里。此外1月19日17时许，日本军用直升机也曾发出遭到中国军舰火控雷达“瞄准”的警告。</p><p style=\"margin-bottom:0px;padding-right:0px;padding-bottom:29px;padding-left:0px;font-size:16px;line-height:28px;font-family:宋体, Arial, sans-serif;text-indent:2em;\">据悉，针对小野寺五典的表述，截至发稿时，中方对此并未作出回应，仅表示正在核实该事件。（方芳）</p><br />",
                    CreatedTime = DateTime.Now,
                    UpdatedTime = DateTime.Now,
                    IsPublished = true,
                    Author = "Admin",
                    Category = newsCategory
                };
            context.Articles.Add(art1);
            for (var i = 1; i <= 12; i++)
            {
                var time = DateTime.Now.AddDays(-2);
                var blog = new Article
                    {
                        Title = "文章" + i,
                        Body = "正文",
                        CreatedTime = time,
                        UpdatedTime = time,
                        StartTime = time,
                        Author = "admin",
                        IsPublished = true,
                        Category = newsCategory
                    };
                var blog2 = new Article
                {
                    Title = "文章-" + i,
                    Body = "正文",
                    CreatedTime = time,
                    UpdatedTime = time,
                    StartTime = time,
                    EndTime = DateTime.Now.AddDays(-1),
                    Author = "admin",
                    IsPublished = true,
                    Category = newsCategory
                };
                context.Articles.Add(blog);
                context.Articles.Add(blog2);
            }
            context.SaveChanges();

            new SiteConfigInit().Init(context);
        }
    }
}